Component({
    properties: {
        value: {
            type: Array,
            value: [],
            observer: "onValue"
        },
        isShow: {
            type: Boolean,
            value: !1,
            observer: "onShow"
        },
        nowTime: {
            type: String,
            observer: function (news, olds, path) {
                this.setData({
                    newValue: news
                })
            }
        }
    },
    data: {
        years: [],
        months: [],
        days: [],
        houre: [],
        hours: [],
        year: '',
        month: '',
        day: '',
        houe: '',
        hous: '',
        tempYearPos: [0],
        tempMonthPos: [0],
        tempDayPos: [0],
        tempHourPos: [0],
        tempHourPos1: [0],
        showPicker: !1,
        newData: '',
        value: [0, 0, 0, 0, 0, 0],
        values: [0, 0, 0, 0, 0, 0],
        newValue: ""
    },
    attached: function () {
        // console.log('打开了')
    },
    methods: {
        onTouchmask: function (t) {
        },
        onCacnelClick: function (t) {
            this.triggerEvent("cancelclick", {});
        },
        initAddresssSelectSheelt: function (val) {
            var that = this;
            var t = new Date()
            var tY = t.getFullYear()//当年
            var tM = t.getMonth() + 1//当月 
            var tD = t.getDate()//当天
            let y = []//年
            let e = []//月
            let s = []//日
            let hs = []//起
            let he = []//止
            if (val === '请选择时间') {
                that.renderInitData()
            } else if (t.getTime() >= new Date((val.split('~')[0] + ':00').replace(/-/g, '/'))) { // 时间已经过去
                that.renderInitData()
            } else if (new Date((val.split('~')[0] + ':00').replace(/-/g, '/')).getTime() < new Date((t.getFullYear() + '/' + (t.getMonth() + 1) + '/' + t.getDate() + ' 24:00:00')).getTime() && new Date((val.split('~')[0] + ':00').replace(/-/g, '/')).getTime() > t.getTime()) { //时间属于今天
                that.renderInitData1(val)
            } else {
                let temp = new Date((val.split('~')[0] + ':00').replace(/-/g, '/'));
                var tpY = temp.getFullYear()//当年
                var tpM = temp.getMonth() + 1//当月 
                var tpD = temp.getDate()//当天
                var tsH = temp.getHours() > 10 ? temp.getHours() : '0' + temp.getHours()//起
                var teH = +val.split('~')[1].slice(0, 2) > 10 ? +val.split('~')[1].slice(0, 2) : '0' + (+val.split('~')[1].slice(0, 2))//止
                if (tY < tpY) { //下年
                    for (let m = 1; m <= 12; m++) {
                        e.push(m >= 10 ? m : ('0' + m))
                    }
                    for (let z = tY; z <= tY + 1; z++) {
                        y.push(z >= 10 ? z : ('0' + z))
                    }
                    s = that.getDays1(tpY, tpM);
                    hs = that.getHourss1()
                    he = that.getHouree1()
                    that.setData({
                        years: y,
                        months: e,
                        days: s,
                        hours: hs,
                        houre: he,

                    })
                    let v1 = that.getArrayIndex(y, tpY)
                    let v2 = that.getArrayIndex(e, tpM)
                    let v3 = that.getArrayIndex(s, tpD)
                    let v4 = that.getArrayIndex(hs, tsH)
                    let v5 = that.getArrayIndex(he, teH)
                    // setTimeout(() => {
                    that.setData({
                        value: [v1, v2, v3, v4, 0, v5],
                        values: [v1, v2, v3, v4, 0, v5],
                        year: y[v1],//赋值
                        month: e[v2],
                        day: s[v3],
                        houe: he[v5],
                        hous: hs[v4],
                    })
                    // }, 100);
                    return;
                } else { // 本年
                    for (let m = tM; m <= 12; m++) {
                        e.push(m >= 10 ? m : ('0' + m))
                    }
                    for (let z = tY; z <= tY + 1; z++) {
                        y.push(z >= 10 ? z : ('0' + z))
                    }
                    if (tM == tpM) { //当月
                        s = that.getDays(tY, tpM);
                        if (tD == tpD) {  //当天
                            hs = that.getHours()
                            he = that.getHours1()
                        } else { //非当天
                            hs = that.getHourss1()
                            he = that.getHouree1()
                        }
                    } else { //下一月
                        s = that.getDays1(tpY, tpM);
                        hs = that.getHourss1()
                        he = that.getHouree1()
                        that.setData({
                            years: y,
                            months: e,
                            days: s,
                            hours: hs,
                            houre: he,
                        })
                    }
                    let v1 = that.getArrayIndex(y, tpY)
                    let v2 = that.getArrayIndex(e, tpM)
                    let v3 = that.getArrayIndex(s, tpD)
                    let v4 = that.getArrayIndex(hs, tsH)
                    let v5 = that.getArrayIndex(he, teH)
                    // setTimeout(() => {
                    that.setData({
                        value: [v1, v2, v3, v4, 0, v5],
                        values: [v1, v2, v3, v4, 0, v5],
                        year: y[v1],//赋值
                        month: e[v2],
                        day: s[v3],
                        houe: he[v5],
                        hous: hs[v4],
                    })
                    // }, 100);
                }
            }
        },
        bindChange: function (e) {
            let that = this;
            let today = new Date()
            let targtYear = today.getFullYear() // 目标年
            let targtMonth = today.getMonth() + 1; //目标月
            let targtDate = today.getDate(); //目标天
            var val = e.detail.value;
            var t = that.data.values;
            if (val[0] != t[0]) { // 年
                if (val[0] == 0) { // 今年
                    let e = []//月
                    let s = []//日
                    let hs = []//起
                    let he = []//止
                    for (let m = (today.getMonth() + 1); m <= 12; m++) {
                        e.push(m >= 10 ? m : ('0' + m))
                    }
                    if (e[0] == targtMonth) { //本月
                        s = that.getDays(targtYear, targtMonth);
                        if (s[0] == targtDate) { //本天
                            hs = that.getHours()
                            he = that.getHours1()
                        } else { //非本天
                            hs = that.getHourss1()
                            he = that.getHouree1()
                        }
                    } else { //下月
                        s = that.getDays1(targtYear, 1);
                        hs = that.getHourss1()
                        he = that.getHouree1()
                    }
                    that.setData({
                        months: e,
                        days: s,
                        hours: hs,
                        houre: he,
                        value: [val[0], 0, 0, 0, 0, 0],
                        values: [val[0], 0, 0, 0, 0, 0],
                        year: that.data.years[val[0]],//赋值
                        month: e[0],
                        day: s[0],
                        houe: he[0],
                        hous: hs[0],
                    })

                } else { //下一年
                    let targtY = targtYear + 1;
                    let e = []//月
                    for (let m = 1; m <= 12; m++) {
                        e.push(m >= 10 ? m : ('0' + m))
                    }
                    let s = this.getDays1(targtY, 1);
                    let hs = that.getHourss1()
                    let he = that.getHouree1()
                    this.setData({
                        months: e,
                        days: s,
                        hours: hs,
                        houre: he,
                        value: [val[0], 0, 0, 0, 0, 0],
                        values: [val[0], 0, 0, 0, 0, 0],
                        year: that.data.years[val[0]],//赋值
                        month: e[0],
                        day: s[0],
                        houe: he[0],
                        hous: hs[0],
                    })
                }
                return;
            }
            if (t[1] != val[1]) { //月
                let s = []//日
                let hs = []//起
                let he = []//止
                if (that.data.years[val[0]] == targtYear) { // 本年
                    if (that.data.months[val[1]] == targtMonth) {//本月
                        s = that.getDays(that.data.years[val[0]], that.data.months[val[1]]);
                        if (s[0] == targtDate) { //本天
                            hs = this.getHours()
                            he = this.getHours1()
                        } else { // 非本天
                            hs = that.getHourss1()
                            he = that.getHouree1()
                        }
                    } else { //非本月
                        s = that.getDays1(that.data.years[val[0]], that.data.months[val[1]]);
                        hs = that.getHourss1()
                        he = that.getHouree1()
                    }
                    that.setData({
                        days: s,
                        hours: hs,
                        houre: he,
                        value: [val[0], val[1], 0, 0, 0, 0],
                        values: [val[0], val[1], 0, 0, 0, 0],
                        year: that.data.years[val[0]],//赋值
                        month: that.data.months[val[1]],
                        day: s[0],
                        houe: he[0],
                        hous: hs[0],

                    })
                } else { //非本年
                    s = that.getDays1(that.data.years[val[0]], that.data.months[val[1]]);
                    let hs = that.getHourss1()
                    let he = that.getHouree1()
                    that.setData({
                        days: s,
                        hours: hs,
                        houre: he,
                        value: [val[0], val[1], 0, 0, 0],
                        values: [val[0], val[1], 0, 0, 0],
                        year: that.data.years[val[0]],//赋值
                        month: that.data.months[val[1]],
                        day: s[0],
                        houe: he[0],
                        hous: hs[0],
                    })
                }
                return;
            }
            if (t[2] != val[2]) { //日
                let hs = []//起
                let he = []//止
                if (that.data.years[val[0]] == targtYear && that.data.months[val[1]] == targtMonth && that.data.days[val[2]] == targtDate) { //本年本月本日
                    hs = that.getHours()
                    he = that.getHours1()

                } else {
                    hs = that.getHourss1()
                    he = that.getHouree1()
                }
                that.setData({
                    hours: hs,
                    houre: he,
                    value: [val[0], val[1], val[2], 0, 0, 0],
                    values: [val[0], val[1], val[2], 0, 0, 0],
                    year: that.data.years[val[0]],//赋值
                    month: that.data.months[val[1]],
                    day: that.data.days[val[2]],
                    houe: he[0],
                    hous: hs[0],
                })
                return
            }
            if (t[3] != val[3]) { //时起
                let n = val[3]
                that.setData({
                    value: [val[0], val[1], val[2], val[3], 0, n],
                    values: [val[0], val[1], val[2], val[3], 0, n],
                    year: that.data.years[val[0]],//赋值
                    month: that.data.months[val[1]],
                    day: that.data.days[val[2]],
                    hous: that.data.hours[val[3]],
                    houe: that.data.houre[n],
                })
                return
            }
            if (t[5] != val[5]) { //时止
                var n1 = val[3]
                if (val[3] - val[5] >= 1) {
                    n1 = val[3] - (val[3] - val[5])
                }
                that.setData({
                    value: [val[0], val[1], val[2], n1, 0, val[5]],
                    values: [val[0], val[1], val[2], n1, 0, val[5]],
                    year: that.data.years[val[0]],//赋值
                    month: that.data.months[val[1]],
                    day: that.data.days[val[2]],
                    hous: that.data.hours[n1],
                    houe: that.data.houre[val[5]],
                })
                return
            }


        },
        onShow: function () {
            this.initAddresssSelectSheelt(this.data.newValue)
        },
        // 确定选中
        confirmAddress: function () {
            let timeValue = this.data.year + '-' + this.data.month + '-' + this.data.day + ' ' + this.data.hous + ':00' + '~' + this.data.houe + ':00';
            this.triggerEvent("sureclick", {
                value: timeValue
            });
        },
        closePickerAddre: function () {
            this.triggerEvent("cancelclick", {});
        },
        renderInitData: function () {
            let that = this;
            let today = new Date()
            let targtYear = today.getFullYear() // 目标年
            let targtMonth = today.getMonth() + 1; //目标月
            let targtDate = today.getDate(); //目标天
            let y = []//年
            let e = []//月
            let s = []//日
            let hs = []//起
            let he = []//止
            for (let m = (today.getMonth() + 1); m <= 12; m++) {
                e.push(m >= 10 ? m : ('0' + m))
            }
            for (let z = targtYear; z <= targtYear + 1; z++) {
                y.push(z >= 10 ? z : ('0' + z))
            }
            if (e[0] == targtMonth) { //本月
                s = that.getDays(targtYear, targtMonth);
                if (s[0] == targtDate) { //本天
                    hs = that.getHours()
                    he = that.getHours1()
                } else { //非本天
                    hs = that.getHourss1()
                    he = that.getHouree1()
                }
            } else { //下月
                s = that.getDays1(targtYear, 1);
                hs = that.getHourss1()
                he = that.getHouree1()
            }
            that.setData({
                years: y,
                months: e,
                days: s,
                hours: hs,
                houre: he,
                year: y[0],//赋值
                month: e[0],
                day: s[0],
                houe: he[0],
                hous: hs[0],
                value: [0, 0, 0, 0, 0, 0],
                values: [0, 0, 0, 0, 0, 0],
            })
        },
        renderInitData1: function (val) {
            let that = this;
            let today = new Date()
            let targtYear = today.getFullYear() // 目标年
            let targtMonth = today.getMonth() + 1; //目标月
            let targtDate = today.getDate(); //目标天
            let y = []//年
            let e = []//月
            let s = []//日
            let hs = []//起
            let he = []//止
            for (let m = (today.getMonth() + 1); m <= 12; m++) {
                e.push(m >= 10 ? m : ('0' + m))
            }
            for (let z = targtYear; z <= targtYear + 1; z++) {
                y.push(z >= 10 ? z : ('0' + z))
            }
            if (e[0] == targtMonth) { //本月
                s = that.getDays(targtYear, targtMonth);
                if (s[0] == targtDate) { //本天
                    hs = that.getHours()
                    he = that.getHours1()
                } else { //非本天
                    hs = that.getHourss1()
                    he = that.getHouree1()
                }
            } else { //下月
                s = that.getDays1(targtYear, 1);
                hs = that.getHourss1()
                he = that.getHouree1()
            }
            let tsH = val.split('~')[0].slice(11, 13)
            let teH = val.split('~')[1].slice(0, 2)
            let v4 = that.getArrayIndex(hs, tsH)
            let v5 = that.getArrayIndex(he, teH)
            that.setData({
                years: y,
                months: e,
                days: s,
                hours: hs,
                houre: he,
                year: y[0],//赋值
                month: e[0],
                day: s[0],
                houe: he[0],
                hous: hs[0],
                value: [0, 0, 0, v4, 0, v5],
                values: [0, 0, 0, v4, 0, v5],
            })
        },
        showPickerFunction: function () {
            var that = this;
            setTimeout(function () {
                var t = that.getRefreshData();
                t.showPicker = that.data.isShow;
                that.setData(t);
            }, 100)
        },
        getHours: function () {
            var hs = [];
            for (var o = new Date().getHours(); o <= 23; o++) {
                var n = 0;
                n = o < 10 ? "0" + o : o, hs.push(n);
            }
            return hs
        },
        getHours1: function () {
            var hs = [];
            for (var o = new Date().getHours() + 1; o <= 24; o++) {
                var n = 0;
                n = o < 10 ? "0" + o : o, hs.push(n);
            }
            return hs
        },
        getHourss1: function () {
            var hs = [];
            for (var o = 0; o <= 23; o++) {
                var n = 0;
                n = o < 10 ? "0" + o : o, hs.push(n);
            }
            return hs
        },
        getHouree1: function () {
            var hs = [];
            for (var o = 1; o <= 24; o++) {
                var n = 0;
                n = o < 10 ? "0" + o : o, hs.push(n);
            }
            return hs
        },
        getDays: function (t, a) {
            var e = [];
            a = parseInt(a, 10);
            for (var s = new Date(t, a, 0).getDate(), h = new Date().getDate(); h <= s; h++) {
                var o = 0;
                o = h < 10 ? "0" + h : h, e.push(o);
            }
            return e;
        },
        getDays1: function (t, a) { // 选下一年
            var e = [];
            a = parseInt(a, 10);
            for (var s = new Date(t, a, 0).getDate(), h = 1; h <= s; h++) {
                var o = 0;
                o = h < 10 ? "0" + h : h, e.push(o);
            }
            return e;
        },
        getArrayIndex: function (arr, obj) {
            var i = arr.length;
            while (i--) {
                if (arr[i] == obj) {
                    return i;
                }
            }
            return -1;
        }
    }
});